/**
 * Copyright (c) 2020 qar All rights reserved.
 * <p>
 * https://www.qar.io
 * <p>
 * 版权所有，侵权必究！
 */

package com.example.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.example.constant.Constant;
import com.example.dao.BaseClassDao;
import com.example.dto.GenBaseClassDTO;
import com.example.dto.SysDictDataDTO;
import com.example.entity.BaseClassEntity;
import com.example.model.page.PageData;
import com.example.mybatis.service.impl.BaseServiceImpl;
import com.example.service.BaseClassService;
import com.example.utils.ConvertUtils;
import com.example.utils.JsonUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * 基类管理
 *
 * @author Mark sunlightcs@gmail.com
 */
@Service
public class BaseClassServiceImpl extends BaseServiceImpl<BaseClassDao, BaseClassEntity> implements BaseClassService {

    @Override
    public PageData<GenBaseClassDTO> page(Map<String, Object> params) {
        IPage<BaseClassEntity> page = baseDao.selectPage(
            getPage(params, Constant.CREATE_DATE, false),
            getWrapper(params)
        );
        return getPageData(page, GenBaseClassDTO.class);
    }

//    @Override
//    public PageData<SysUserDTO> selectPage(SysQueryUserDTO sysQueryUserDTO) {
//        Map<String, Object> params = JsonUtils.convertClassToMap(sysQueryUserDTO);
//        IPage<SysUserEntity> page = baseDao.selectPage(
//                getPage(params, Constant.CREATE_DATE, false),
//                null // getWrapper(params)
//        );
//        return getPageData(page, SysUserDTO.class);
//    }

    @Override
    public List<GenBaseClassDTO> list() {
        return ConvertUtils.sourceToTarget(baseDao.selectList(null), GenBaseClassDTO.class);
    }

    private QueryWrapper<BaseClassEntity> getWrapper(Map<String, Object> params){
        String code = (String)params.get("code");

        QueryWrapper<BaseClassEntity> wrapper = new QueryWrapper<>();
        wrapper.like(StringUtils.isNotEmpty(code), "code", code);

        return wrapper;
    }
}